package com.mz.ozy.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;

import com.mz.ozy.R;
import com.mz.ozy.activity.find.MyIntegralActivity;
import com.mz.ozy.activity.find.WholeStrategyActivity;
import com.mz.ozy.activity.home.HomeActivity1;
import com.mz.ozy.activity.login.PhoneSmsLoginActivity;
import com.mz.ozy.activity.login.SplashActivity;
import com.mz.ozy.activity.me.MeActivity;
import com.mz.ozy.activity.me.ObShopActivity1;
import com.mz.ozy.activity.shop.MallActivity;
import com.mz.ozy.activity.shop.MallActivity1;
import com.mz.ozy.constants.Constants;
import com.mz.ozy.utils.LanguageUtils;
import com.mz.ozy.utils.SPUtils;
import com.mz.ozy.widget.dialog.NotVipDialog;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends TabActivity {
    public static TabHost tabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LanguageUtils.switchLanguage(this);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        QMUIStatusBarHelper.translucent(this);
        init();

    }

    private void init() {

        String vip = SPUtils.getInstance(this).getString(Constants.PREE.IS_VIP, "0");
        if ("0".equals(vip)) {
            Constants.isVip = false;
        } else {
            Constants.isVip = true;
        }

        tabHost = getTabHost();
        tabHost.setup();
        Intent homeInTent = new Intent(this, HomeActivity1.class);
        TabHost.TabSpec homeSpec = tabHost.newTabSpec("home");
        homeSpec.setIndicator(getTabHostItem(R.drawable.home_selector, R.string.home));
        homeSpec.setContent(homeInTent);
        tabHost.addTab(homeSpec);


       /* Intent dappInTent = new Intent(this, AssetsActivity.class);
        TabHost.TabSpec daSpec = tabHost.newTabSpec("dapp");
        daSpec.setIndicator(getTabHostItem(R.drawable.dapp_selector, R.string.dapp));
        daSpec.setContent(dappInTent);
        tabHost.addTab(daSpec);*/

        Intent infoInTent = new Intent(this, MallActivity1.class);
        //Intent infoInTent = new Intent(this, ObShopActivity1.class);
        TabHost.TabSpec infoSpec = tabHost.newTabSpec("mall");
        infoSpec.setIndicator(getTabHostItem(R.drawable.mall_selector, R.string.sort_tab));
        infoSpec.setContent(infoInTent);
        tabHost.addTab(infoSpec);

        Intent gameIntent = new Intent(this, MyIntegralActivity.class);
        TabHost.TabSpec gameSpec = tabHost.newTabSpec("game");
        gameSpec.setIndicator(getTabHostItem(R.drawable.game_selector, R.string.game_title));
        gameSpec.setContent(gameIntent);
        tabHost.addTab(gameSpec);

        Intent asInTent = new Intent(this, WholeStrategyActivity.class);
        TabHost.TabSpec asSpec = tabHost.newTabSpec("bus");
        asSpec.setIndicator(getTabHostItem(R.drawable.assets_selector, R.string.info_tab));
        asSpec.setContent(asInTent);
        tabHost.addTab(asSpec);

        Intent meInTent = new Intent(this, MeActivity.class);
        TabHost.TabSpec meSpec = tabHost.newTabSpec("me");
        meSpec.setIndicator(getTabHostItem(R.drawable.me_selector, R.string.me));
        meSpec.setContent(meInTent);
        tabHost.addTab(meSpec);

        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId) {
//                if (!Constants.isVip) {
//                    NotVipDialog dialog = new NotVipDialog(MainActivity.this);
//                    dialog.showDialog();
//                    return;
//                }

                if (tabId.equals("me")) {   //第一个标签
                    if (!Constants.isLogin) {
                        startActivity(new Intent(MainActivity.this, PhoneSmsLoginActivity.class));
                        finish();
                    }
                }
            }
        });

    }

    public View getTabHostItem(int imageId, int textId) {
        View tab = LayoutInflater.from(this).inflate(R.layout.tab_item, null);
        ImageView image = (ImageView) tab.findViewById(R.id.tab_image);
        TextView text = (TextView) tab.findViewById(R.id.tab_text);
        image.setImageResource(imageId);
        text.setText(textId);
        return tab;
    }

    @OnClick({R.id.iv_center_find})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_center_find:
//                if (!Constants.isVip) {
//                    NotVipDialog dialog = new NotVipDialog(MainActivity.this);
//                    dialog.showDialog();
//                    return;
//                }
                tabHost.setCurrentTab(2);
                break;
        }
    }
}
